<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 200px;
            height: 200px;
            background: green;
        }
    </style>
    <script>
        var i = 1;
        function fn(){
            var div;
            div = document.getElementById('div1');
            // console.log(i);
            // div.style.background = 'pink';
            
            if(i == 1){
                div.style.background = 'pink';
                // console.log(i);
                i--;
            }else if(i == 0){
                div.style.background = 'blue';   
                // console.log(i);
                i--;
            }else if(i == -1){
                div.style.background = 'green'; 
                i=i+2;
            }
        }
    </script>
</head>
<body>
    <div id="div1" onclick="fn()"></div>
</body>
</html>